
import java.util.Random;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-04-23
 * Time: 15:20
 */

public class TESTDEMO {

    public static void main(String[] args) {
        double num = 1.0;
        int n = 1;
        String str = "123";
        switch(str){
            case 1:
                break;
        }
    }

//随机数生成
    public static void main17(String[] args) {
        Random random = new Random();
        int rd = random.nextInt(101);//[0,100)

       //int rd = (int)(Math.random()*(101-1)+1);
        //int rd = (int)(Math.random()*(10-1)+1);
        System.out.println(rd);

        while(true){
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入你的数字");
            int n = sc.nextInt();
            if(rd==n){
                System.out.println(n+"猜对了");
                break;
            }
            else if(n<rd){
                System.out.println("猜小了");
            }
            else{
                System.out.println("猜大了");
            }
        }


    }


//三种输出
    public static void main16(String[] args) {
        System.out.println("输出且换行");
        System.out.print("输出且不换行");
        System.out.printf("%s\n","换行了吗");//格式化输出
    }
//输入
    public static void main15(String[] args) {
       Scanner sc = new Scanner(System.in);
        System.out.println("请在输入你的姓名");
        //输入一行
        String str = sc.nextLine();
        System.out.println(str);
        System.out.println("请输入你的年龄");
        //输入一个整型
        int n = sc.nextInt();
        System.out.println("输入你的年龄");
        System.out.println(n);
        //输入一个小数
        float f = sc.nextFloat();
        System.out.println(f);
        //sc.next 碰到空格结束
        String ch = sc.next();
        System.out.println(ch);
    }
    //死循环
    public static void main14(String[] args) {
//        while(true){
//            System.out.println("hehe");
//        }
   }
//do while 循环语句
    public static void main13(String[] args) {
        int i = 0;
        do {
            System.out.println("haha");
        }while(i != 0);
    }
//continue在for循环中不会导致死循环
    public static void main12(String[] args) {
        for (int i = 0; i < 5; i++) {
            if(i==1){
                continue;
            }
            System.out.println(i+"hehe");
        }
    }
//for循环求1-5每个数阶乘的和 单个循环
    public static void main11(String[] args) {
        int ret = 1;
        int sum = 0;
        for (int i = 1; i <=5 ; i++) {
            ret *= i;
            sum+=ret;
        }
        System.out.println(sum);
    }
//for循环求1-5每个数阶乘的和 循环嵌套
    public static void main10(String[] args) {
        int sum = 0;
        for (int j = 1; j <=5; j++) {
            int ret = 1;
            for (int i = 1; i <= j; i++) {
                ret*=i;
            }
            sum+=ret;
        }
        System.out.println(sum);
    }

//for循环求5的阶乘
    public static void main9(String[] args) {

        int ret = 1;
        for (int i = 1; i <= 5; i++) {
            ret*=i;
        }
        System.out.println(ret);
    }
    
//求1-100里能被15整除的数
    public static void main8(String[] args) {
        int i = 1;
        while(i<=100){
            if(i % 15 != 0){
                i++;//改变i的值防止死循环
                continue;
            }
            System.out.println(i);
            i++;//改变i的值使循环体继续往下走
        }
    }
//continue 会跳过这趟里continue后面的代码，所以这一趟不会打印，i的值也一直没变，所以死
    public static void main7(String[] args) {
        int i = 1;
        while(i<=10){
            if(i==2) {
                //i++;
                continue;
            }
            System.out.println(i+"lala");
            i++;
        }
    }


//else的悬挂问题
    public static void main6(String[] args) {
        int a = 10;
        int b = 20;
        if(a==1){
            if(b==20)
                System.out.println("hehe");
        }

        else
                System.out.println("haha");

    }

    //判断闰年
    public static void main5(String[] args) {
        //输入
       Scanner sc = new Scanner(System.in);
       //多组输入 sc.hasNext()
       while(sc.hasNext())
       {
           int year = sc.nextInt();
           //将年份分为世纪年和普通年
           //世纪年
           if(year % 100 ==0){
               if(year % 400 ==0){
                   System.out.println(year+"是润年");
               }
               else{
                   System.out.println(year+"不是闰年");
               }
           }
           //普通年
           else{
               if(year % 4 == 0){
                   System.out.println(year+"是闰年");
               }
               else {
                   System.out.println(year+"不是闰年");
               }
           }

       }

    }

//1-100中能被15整除的数
    public static void main4(String[] args) {
        int i = 1;
        while(i <= 100){
            if(i % 15 !=0){
                i++;
                continue;
            }
                System.out.println(i);
                i++;
        }
    }






        //将每个数字的阶乘都算出来
    public static void main3(String[] args) {
        int j = 1;
        int sum = 0;
        while(j<=5){
            int i = 1;
            int ret = 1;
            while(i<=j){
                ret *= i;
                i++;
            }
            sum += ret;
            j++;

        }
        System.out.println(sum);
    }




        //求1-5的阶乘之和 优化
    public static void main2(String[] args) {
        int i = 1;
        int ret = 1;
        int sum = 0;
        while(i<=5)
        {
            ret *= i;
            sum += ret;
            i++;
        }
        System.out.println(sum);
    }



    //求和
    public static void main1(String[] args) {
        int i = 1;
        int sum = 0;//1-100的和
        int sumEve = 0;//1-100偶数的和
        int sumOdd = 0;//1-100奇数的和
        while(i <= 100){
            sum+=i;
            i++;
        }
        //o偶数
        i = 2;
        while(i <= 100){
            sumEve += i;
            i+=2;
        }
        //奇数的和
        i = 1;
        while(i <= 100){
            sumOdd += i;
            i+=2;
        }
        System.out.println(i);
        System.out.println(sum);
        System.out.println(sumEve);
        System.out.println(sumOdd);
    }
}
